package com.zking.entity;

import com.zking.util.Tools;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Arrays;


/**
 * @author Tony
 * 商品表对应的实体类
 */
public class Product implements Serializable{
	private static final long serialVersionUID = 1L;
	private int ep_id;//商品的id
	private String ep_name;//商品的名称
	private String ep_description;//商品的描述
	private double ep_price;//商品的价格
	private int ep_stock;//商品的库存
	private int epc_id;//大类id,这玩意连数据库外键约束都没有，乱糟糟的，不建议用
	private int epc_child_id;//小类id
	private String ep_file_name;//商品图片的名称
	private int count=1; //购物车中该商品的数量

	private byte[] ep_image_bytes = new byte[2024];
	
	public Product() {
		super();
	}
	
	public Product(String epName, String epDescription, int epcId, int epcChildId,
			String epFileName,double epPrice, int epStock, InputStream image) throws IOException {
		super();
		ep_name = epName;
		ep_description = epDescription;
		ep_price = epPrice;
		ep_stock = epStock;
		epc_id = epcId;
		epc_child_id = epcChildId;
		ep_file_name = epFileName;
		ep_image_bytes = Tools.InputStreamToByte(image);
	}

	public Product(String name, String description, double price, int count, InputStream imageContent) throws IOException {
		super();
		ep_name=name;
		ep_description=description;
		ep_price=price;
		ep_stock=count;

		ep_image_bytes= Tools.InputStreamToByte(imageContent);
	}

	public Product(int id, String epName, String epDescription, double epPrice, int epStock, int parentId, int epcChildId, InputStream stream) throws IOException {
		super();
		ep_id = id;
		ep_name = epName;
		ep_description = epDescription;
		ep_price = epPrice;
		ep_stock = epStock;
		epc_child_id = epcChildId;
		epc_id = parentId;
		if(stream!=null){
			ep_image_bytes = Tools.InputStreamToByte(stream);
		}
		else{
			ep_image_bytes = null;
		}
	}

	public byte[] getEp_image_bytes() {
		return ep_image_bytes;
	}

	@Override
	public String toString() {
		return "Product{" +
				"ep_id=" + ep_id +
				", ep_name='" + ep_name + '\'' +
				", ep_description='" + ep_description + '\'' +
				", ep_price=" + ep_price +
				", ep_stock=" + ep_stock +
				", epc_id=" + epc_id +
				", epc_child_id=" + epc_child_id +
				", ep_file_name='" + ep_file_name + '\'' +
				", count=" + count +
				", ep_image_bytes=" + Arrays.toString(ep_image_bytes) +
				'}';
	}

	public void setEp_image_bytes(byte[] ep_image_bytes) {
		this.ep_image_bytes = ep_image_bytes;
	}

	public Product(int epId, String epName, String epDescription,
				   double epPrice, int epStock, int epcId, int epcChildId,
				   String epFileName, byte[] image) {
		super();
		ep_id = epId;
		ep_name = epName;
		ep_description = epDescription;
		ep_price = epPrice;
		ep_stock = epStock;
		epc_id = epcId;
		epc_child_id = epcChildId;
		ep_file_name = epFileName;
		ep_image_bytes = image;
	}
	
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public int getEp_id() {
		return ep_id;
	}
	public void setEp_id(int epId) {
		ep_id = epId;
	}
	public String getEp_name() {
		return ep_name;
	}
	public void setEp_name(String epName) {
		ep_name = epName;
	}
	public String getEp_description() {
		return ep_description;
	}
	public void setEp_description(String epDescription) {
		ep_description = epDescription;
	}
	public double getEp_price() {
		return ep_price;
	}
	public void setEp_price(double epPrice) {
		ep_price = epPrice;
	}
	public int getEp_stock() {
		return ep_stock;
	}
	public void setEp_stock(int epStock) {
		ep_stock = epStock;
	}
	public int getEpc_id() {
		return epc_id;
	}
	public void setEpc_id(int epcId) {
		epc_id = epcId;
	}
	public int getEpc_child_id() {
		return epc_child_id;
	}
	public void setEpc_child_id(int epcChildId) {
		epc_child_id = epcChildId;
	}
	public String getEp_file_name() {
		return ep_file_name;
	}
	public void setEp_file_name(String epFileName) {
		ep_file_name = epFileName;
	}
	
	public int hashCode() {
		return -1;
	}
	public boolean equals(Object obj) {
		//判断两个商品是相等
		//
		if(obj instanceof Product){
			Product product = (Product) obj;
			if(product.ep_id ==this.ep_id){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}


}
